package utils.path.support;

import javax.servlet.ServletConfig;

import utils.path.ConfigPath;
import utils.test.Assert;

/**
 * web容器方式加域配置
 */
public class WebContextConfigPath extends ConfigPath {
	
	private ServletConfig config;
	
	public WebContextConfigPath(String[] locations, ServletConfig config) {
		super(locations);
		this.config = config;
	}
	
	private String getClassRootPath(){
		return this.config.getServletContext().getRealPath("/");
	}
	
	@Override
	public String[] processConfigPath() {
		Assert.isNotNull(this.locations, "配置路径不可为空");
		Assert.hasLength(this.locations, "配置路径不可为空");
		String rootPath = getClassRootPath();
		for (int i=0;i<this.locations.length;i++) {
			locations[i] = rootPath + locations[i];
			locations[i] = locations[i].replaceAll("\\\\", "/");
		}
		return this.locations;
	}
}
